﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class TabControlPlusStyle4EffectForm : ItemFormTemplate
    {
        public TabControlPlusStyle4EffectForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件效果\\选项卡\\TabControlPlusStyle4EffectForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();
        }

        public override void ShowView()
        {
            base.ShowView();
        }

        public override void HideView()
        {
            base.HideView();
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.TabBar.TabItem.RoundSize = new RoundCorner(0);
            this.demo_control.TabBar.TabItem.Size = new System.Drawing.Size(120, 24);
            this.demo_control.TabBar.Padding = new System.Windows.Forms.Padding(0, 0, 0, 3);
            this.demo_control.TabBarDrawBackground += this.Demo_control_TabBarDrawBackground;

        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Location = new Point((control.Width - this.demo_control.Width) / 2, (control.Height - this.demo_control.Height) / 2);
        }

        private void Demo_control_TabBarDrawBackground(object sender, TabControlPlusTabBarDrawBackgroundEventArgs e)
        {
            TabControlPlus tabControl = (TabControlPlus)sender;
            if (tabControl.TabBar.Padding.Bottom > 0)
            {
                int height = (int)(Math.Ceiling(tabControl.TabBar.Padding.Bottom * tabControl.ScaleDpi));
                SolidBrush line_sb = new SolidBrush(tabControl.StyleAppearance.TabBar.TabItem.Selected.BackColor);
                e.Graphics.FillRectangle(line_sb, new RectangleF(e.Bounds_P.X, e.Bounds_P.Bottom - height, e.Bounds_P.Width, height));
                line_sb.Dispose();
            }
        }

        #endregion
    }
}
